//
//  OBMomentCommentItemViewModel.m
//  WeChat
//
//  Created by 黄柳姣 on 2018/5/3.
//  Copyright © 2018年 obally. All rights reserved.
//

#import "OBMomentCommentItemViewModel.h"
@interface OBMomentCommentItemViewModel ()

/// 评论模型
@property (nonatomic, readwrite, strong) OBCommentModel *comment;

@end
@implementation OBMomentCommentItemViewModel
- (instancetype)initWithComment:(OBCommentModel *)comment
{
    if (self = [super init]) {
        self.comment = comment;
        //正文
        NSMutableAttributedString *contentAttr = [[NSMutableAttributedString alloc] init];
        
        /// : 正文富文本 （还需要匹配超链接 表情 电话号码 @xx）
        NSMutableAttributedString *textAttr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"：%@",comment.content]];
        textAttr.color = OBGlobalBlackTextColor;
        textAttr.font = OBMomentCommentContentFont;
        /// 点击的高亮的
        YYTextBorder *border = [YYTextBorder new];
        border.cornerRadius = 0;
        border.insets = UIEdgeInsetsMake(0, -1, 0, -1);
        border.fillColor = OBMomentTextHighlightBackgroundColor;
        /// XXX （来源）
        NSMutableAttributedString *fromAttr = [[NSMutableAttributedString alloc] initWithString:comment.sender.nick];
        fromAttr.color = OBMomentScreenNameTextColor;
        fromAttr.font = OBMomentCommentScreenNameFont;
        
        /// 拼接 （A回复B：xxxx   或者  A：xxxx）
        [contentAttr appendAttributedString:fromAttr];
        [contentAttr appendAttributedString:textAttr];
        
        /// 统一配置
        contentAttr.lineBreakMode = NSLineBreakByCharWrapping;
        contentAttr.alignment = NSTextAlignmentLeft;
        /// 文本布局
        CGFloat limitWidth = OBMomentCommentViewWidth()-2*OBMomentCommentViewContentLeftOrRightInset;
        YYTextContainer *contentLableContainer = [YYTextContainer containerWithSize:CGSizeMake(limitWidth, MAXFLOAT)];
        contentLableContainer.maximumNumberOfRows = 0;
        YYTextLayout *contentLableLayout = [YYTextLayout layoutWithContainer:contentLableContainer text:contentAttr.copy];
        self.contentLableLayout = contentLableLayout;
        
        
        /// ----------- 尺寸属性 -----------
        CGFloat contentLableW = contentLableLayout.textBoundingSize.width;
        CGFloat contentLableH = contentLableLayout.textBoundingSize.height;
        self.contentLableFrame = CGRectMake(OBMomentCommentViewContentLeftOrRightInset, OBMomentCommentViewContentTopOrBottomInset, contentLableW, contentLableH);
        self.cellHeight = CGRectGetMaxY(self.contentLableFrame)+OBMomentCommentViewContentTopOrBottomInset;
    }
    
    return self;
}
@end
